package com.dyb.nio.future;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.socket.nio.NioSocketChannel;

import java.io.IOException;

/**
 * Netty和Guava的思路是一致的。对应关系为：
 * · Netty的Future接口，可以对应到Guava的ListenableFuture接口。
 * · Netty的GenericFutureListener接口，可以对应到Guava的FutureCallback接口。
 */
public class NettyFuture {

    public void run() throws IOException {
        NioSocketChannel channel = new NioSocketChannel();
        ChannelFuture future = channel.write("msg");
        future.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                // write完成之后回调代码
            }
        });
    }
}
